home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / winlib.lzh / WINLIB / TOOLS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  4.3 KB  |  203 lines

  1. /********************************************************************
  2.  *                                                                    *
  3.  *    WinLIB PRO Revision II: Tools module                            *
  4.  *                                                                    *
  5.  *    Copyright (c) 1994, Bitgate Software                            *
  6.  *                                                                    *
  7.  ********************************************************************/
  8.  
  9. #include <aes.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include "winlib.h"
  14.  
  15. #ifndef __TOOLS__
  16. #define __TOOLS__
  17. #endif
  18.  
  19. /*
  20.  *    Check for intersection of rectangles r1 and r2.
  21.  *    Intersecting rectangle is returned in r1.
  22.  *
  23.  *    Returns FALSE if no intersection
  24.  */
  25. GLOBAL int rc_intersect(GRECT *r1, GRECT *r2)
  26. {
  27.     r1->g_w = min(r1->g_x + r1->g_w, r2->g_x + r2->g_w );
  28.     r1->g_h = min(r1->g_y + r1->g_h, r2->g_y + r2->g_h );
  29.     r1->g_x = max(r1->g_x, r2->g_x);
  30.     r1->g_y = max(r1->g_y, r2->g_y);
  31.     r1->g_w -= r1->g_x;
  32.     r1->g_h -= r1->g_y;
  33.     return (r1->g_w > 0 && r1->g_h > 0) ? TRUE : FALSE;
  34. }
  35.  
  36. GLOBAL int rc_inside(int x, int y, GRECT *r)
  37. {
  38.     return (x > r->g_x && x < (r->g_x + r->g_w) &&
  39.              y > r->g_y && y < (r->g_y + r->g_h));
  40. }
  41.  
  42. /*
  43.  *    Wait until left mousebutton is released
  44.  *
  45.  *    Returns: nothing
  46.  */
  47. GLOBAL void no_click(void)
  48. {
  49.     int dummy, bstate;
  50.  
  51.     graf_mkstate(&dummy, &dummy, &bstate, &dummy);
  52.     if (bstate & 1)
  53.         evnt_button(1, 3, 0, &dummy, &dummy, &dummy, &dummy);
  54. }
  55.  
  56. /*
  57.  *  Check to see if a window is topped
  58.  *
  59.  *  handle = window to check for
  60.  *
  61.  */
  62. GLOBAL int WIsTopped(int handle)
  63. {
  64.     int x;
  65.  
  66.     wind_get(handle, WF_TOP, &x);
  67.     return((x == handle) ? TRUE : FALSE);
  68. }
  69.  
  70. /*
  71.  *    Routine to find out if any windows are W_UNUNTOPPABLE
  72.  *
  73.  *    Returns FALSE if no handle, and a non-zero number of the window
  74.  *                 handle that was found.
  75.  */
  76. GLOBAL int WFindUntoppables(void)
  77. {
  78.     WINDOW *win = WindowChain;
  79.  
  80.     while (win->next) {
  81.         if (win->dominance == D_SWITCHABLE)
  82.             return win->handle;
  83.  
  84.         win = win->next;
  85.     }
  86.  
  87.     return FALSE;
  88. }
  89.  
  90. /*
  91.  *    Find if any windows are on the desktop
  92.  *
  93.  *    Returns TRUE if there are, FALSE if none are opened, skipping the
  94.  *    desktop handle.
  95.  */
  96. GLOBAL BOOL WFindAnyOpen(void)
  97. {
  98.     WINDOW *win = WindowChain;
  99.  
  100.     while (win->next) {
  101.         if ((win->state & W_OPEN) && !(win->state & W_DESKTOP))
  102.             return TRUE;
  103.  
  104.         win = win->next;
  105.     }
  106.  
  107.     return FALSE;
  108. }
  109.  
  110. /*
  111.  *    Find if a specific window is open (not for internal resources)
  112.  *
  113.  *    Returns TRUE if it's already open, FALSE if no windows match the
  114.  *                    given tree number.
  115.  */
  116. GLOBAL BOOL WFindWindow(int treenumber)
  117. {
  118.     WINDOW *win = WindowChain;
  119.  
  120.     while (win->next) {
  121.         if (win->treenumber == treenumber)
  122.             return TRUE;
  123.  
  124.         win = win->next;
  125.     }
  126.  
  127.     return FALSE;
  128. }
  129.  
  130. /*
  131.  *    Routine to find the most dominant window
  132.  *
  133.  *    Returns the dominant window's handle, or FALSE for no window
  134.  */
  135. GLOBAL int WFindDominance(void)
  136. {
  137.     WINDOW *win = WindowChain;
  138.  
  139.     while (win->next) {
  140.         if (win->dominance == D_ALWAYSTOP)
  141.             return win->handle;
  142.  
  143.         win = win->next;
  144.     }
  145.  
  146.     return FALSE;
  147. }    
  148.  
  149. /*
  150.  *    Change the text displayed inside an object
  151.  *    Version 2.0 from XAES Pro
  152.  *
  153.  *    obj  = Address of the tree to modify
  154.  *    idx  = Index of the object to change
  155.  *    txt  = Pointer to text array to put in to the text
  156.  *    fnt  = Font size
  157.  *    just = Justification of text
  158.  *
  159.  *    This routine has been updated to make it "smarter", ie. it now
  160.  *    has the ability to change text inside objects that have been
  161.  *    previously modified under the fix_objects routine.  If you don't
  162.  *    use this routine to change text inside a fixed object, you are
  163.  *    most likely to bomb the system.  Use this routine if doubtful.
  164.  */
  165. GLOBAL void ChangeObjectText(OBJECT *obj, int idx, char *txt, int fnt, int just)
  166. {
  167.     switch(obj[idx].ob_type & 0xFF) {
  168.         case G_USERDEF:
  169.             {
  170.                 EXTINFO *exinf = (EXTINFO *)(obj[idx].ob_spec.userblk->ub_parm);
  171.  
  172.                 exinf->te_ptext = txt;
  173.                 exinf->te_txtlen = (int) strlen(txt);
  174.             }
  175.             break;
  176.  
  177.         default:
  178.             obj[idx].ob_spec.tedinfo->te_ptext = (char *) txt;
  179.             obj[idx].ob_spec.tedinfo->te_txtlen = (int) strlen(txt);
  180.             if (just>0)
  181.                 obj[idx].ob_spec.tedinfo->te_just = just;
  182.             break;
  183.     }
  184. }
  185.  
  186. /*
  187.  *    Change hotkey drawing level
  188.  */
  189. GLOBAL void WHotkeyLevel(int mode)
  190. {
  191.     hotkeylevel = mode;
  192. }
  193.  
  194. /*
  195.  *    Check for any speed-up screen routines
  196.  */
  197. GLOBAL BOOL WCheckSpeedup(void)
  198. {
  199.     if (find_cookie('NVDI'))
  200.         return TRUE;
  201.  
  202.     return FALSE;
  203. }